package com.zhuss.core.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.core.user.CreateUserRoleBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.core.db.dao.ext.UserRoleDao;
import com.zhuss.core.db.entity.UserRole;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.OceanException;
import com.zhuss.util.JsonUtil;

/**
 * 创建用户角色关系 processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("userRoleCreate")
public class UserRoleCreate extends AbstractProcessor<Object, CreateUserRoleBo> implements Processor<Object, CreateUserRoleBo> {

    @Autowired
    private UserRoleDao userRoleDao;
    
    /**
     * 校验
     */
    @Override
    public void check(CreateUserRoleBo bo) throws OceanException {
    	
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(CreateUserRoleBo param) {
    	UserRole record = new UserRole();
    	record.setUserId(param.getUserId());
    	record.setRoleId(param.getRoleId());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	userRoleDao.create(record);
    	param.setTargetId(record.getId());
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(CreateUserRoleBo param) throws OceanException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.基础模块.key());
    	record.setAction(LogActionEnum.用户角色关系建立.key());
    	record.setTargetId(param.getTargetId());
    	record.setTargetName("");
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
		return null;
	}
}
